package com.auto.learning.activity;

import android.app.Activity;
import android.net.Uri;
import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.JsResult;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebStorage.QuotaUpdater;
import android.webkit.WebView;

public abstract class BaseWebChromeClient extends WebChromeClient {
	WebActivity webActivity;
	
	Activity activity;

	public BaseWebChromeClient(WebActivity webActivity) {
		this.webActivity = webActivity;
	}
	
	public BaseWebChromeClient(Activity activity){
		this.activity = activity;
	}

	@Override
	public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
		// TODO Auto-generated method stub
		Log.d("WebView Console", consoleMessage.message() + ":"
				+ consoleMessage.lineNumber());
		return super.onConsoleMessage(consoleMessage);
	}

	@Override
	public boolean onJsAlert(WebView view, String url, String message,
			JsResult result) {
		// TODO Auto-generated method stub
		return super.onJsAlert(view, url, message, result);
	}

	@Override
	public void onProgressChanged(WebView view, int newProgress) {
		// TODO Auto-generated method stub
		super.onProgressChanged(view, newProgress);
		view.requestFocus();
	}

	@Override
	public void onExceededDatabaseQuota(String url, String databaseIdentifier,
			long quota, long estimatedDatabaseSize, long totalQuota,
			QuotaUpdater quotaUpdater) {
		quotaUpdater.updateQuota(estimatedDatabaseSize * 2);
	}

	// For Android 3.0+
	public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
		if (webActivity.mUploadMessage != null)
			return;
		webActivity.mUploadMessage = uploadMsg;
		webActivity.selectImage();
		
		
		// Intent i = new Intent(Intent.ACTION_GET_CONTENT);
		// i.addCategory(Intent.CATEGORY_OPENABLE);
		// i.setType("*/*");
		// startActivityForResult( Intent.createChooser( i, "File Chooser" ),
		// FILECHOOSER_RESULTCODE );
	}

	// For Android < 3.0
	public void openFileChooser(ValueCallback<Uri> uploadMsg) {
		openFileChooser(uploadMsg, "");
	}

	// For Android > 4.1.1
	public void openFileChooser(ValueCallback<Uri> uploadMsg,
			String acceptType, String capture) {
		openFileChooser(uploadMsg, acceptType);
	}
}
